-
Notifications
You must be signed in to change notification settings - Fork 203
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: add useNetworks and useNetworksRelationship hooks #1297
feat: add useNetworks and useNetworksRelationship hooks #1297
Conversation
The latest updates on your projects. Learn more about Vercel for Git ↗︎
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Left a few comments, things look good so far, but the hooks aren't used anywhere?
It's fine if we want to split the effort into multiple PRs, but then let's create another one on top of this one that actually leverages the hooks so we can test it.
packages/arb-token-bridge-ui/src/hooks/useNetworksRelationship.ts
Outdated
Show resolved
Hide resolved
packages/arb-token-bridge-ui/src/hooks/useNetworksRelationship.ts
Outdated
Show resolved
Hide resolved
packages/arb-token-bridge-ui/src/util/wagmi/getPartnerChainsForChain.ts
Outdated
Show resolved
Hide resolved
packages/arb-token-bridge-ui/src/util/wagmi/getPartnerChainsForChain.ts
Outdated
Show resolved
Hide resolved
Co-authored-by: spsjvc <[email protected]>
Co-authored-by: spsjvc <[email protected]>
…onship-to-our-codebase
…onship-to-our-codebase
packages/arb-token-bridge-ui/src/hooks/__tests__/useNetworks.test.ts
Outdated
Show resolved
Hide resolved
function isValidNumber(value: number) { | ||
return !Number.isNaN(value) | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
seems generic enough that it should be in a more common util file?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure about this one, I would move it once it's needed somewhere else. It's only here because the query param library might return null or undefined for a number, I'm not sure we have this case anywhere else.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
not a strong opinion but the name isValidNumber
and what it does in the fn are totally reusable in any other functions when we want to check isNaN
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's keep it here until it's needed elsewhere
@@ -97,6 +108,55 @@ export const AmountQueryParam = { | |||
} | |||
} | |||
|
|||
// Parse chainId to ChainQueryParam or ChainId for orbit chain | |||
function encodeChainQueryParam(chainId: number | null | undefined) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
better be explicit and type the return type too
…onship-to-our-codebase
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
}) | ||
}) | ||
describe('when `destinationChainId` is valid', () => { | ||
it('and `sourceChainId` is valid should not do anything', () => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
so right now i can read this line and understand it properly because I've been looking at this PR
but i worry down the line this doesn't have a very high readability
plus, both source chain id and destination chain id should be equally important conditions, so i would do this instead:
describe('when `destinationChainId` is valid and `sourceChainId` is valid', () => {
it('should not do anything', () => {}
}
describe('when `destinationChainId` is valid and `sourceChainId` is invalid', () => {
it('should set `sourceChainId`', () => {}
}
...
There are 2 vars with 3 possible values each (undefined/valid/invalid) so there should be 3x3 = 9 cases here
i see them all in place in this file but they should have parallel status given that the 2 vars' initial values have no dependency on each other
const resultWithSepoliaOrbitChain = sanitizeQueryParams({ | ||
sourceChainId: 2222, | ||
destinationChainId: ChainId.ArbitrumSepolia | ||
}) | ||
expect(resultWithSepoliaOrbitChain).toEqual({ | ||
sourceChainId: 2222, | ||
destinationChainId: ChainId.ArbitrumSepolia | ||
}) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
other than testnet, i'd also add a test for orbit <-> arb one and orbit <-> arb nova to make sure it doesn't only go to arb one
and never to arb nova
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
Summary
See #1295
Steps to test
There should be no change visible to the users